using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace Cores
{
    public class Connection
    {
        private String _connString;
        private SqlConnection _connObj;

        public String ConnString
        {
            get { return _connString; }
            set { _connString = value; }
        }

        public SqlConnection ConnObj
        {
            get { return _connObj; }
            set { _connObj = value; }
        }

        public Connection()
        {
            ConnString = "Data Source=.;Initial Catalog=DatVeOnline;Integrated Security=SSPI;";
        }

        public Connection(String connStr)
        {
            ConnString = connStr;
        }

        public SqlConnection Connect()
        {
            try
            {
                ConnObj = new SqlConnection(ConnString);
                ConnObj.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error from sever", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return null;
            }
            return ConnObj;
        }

        public SqlConnection Disconnect()
        {
            ConnObj.Close();
            return ConnObj;
        }
    }
}
